import java.util.*;
public class CountPalindromicSubsequence {
  public int countPalindromicSubsequence(String s) {
    int[] first = new int[26];
    int[] last = new int[26];
    Arrays.fill(first, -1);
    Arrays.fill(last, -1);
    for (int i = 0; i < s.length(); i++) {
      int c = s.charAt(i) - 'a';
      if (first[c] == -1) first[c] = i;
      last[c] = i;
    }
    int result = 0;
    for (int i = 0; i < 26; i++) {
      if (first[i] == last[i]) continue;
      Set<Character> set = new HashSet<>();
      for (int j = first[i] + 1; j < last[i]; j++) {
        set.add(s.charAt(j));
      }
      result += set.size();
    }
    return result;
  }

  public static void main(String[] args) {
    CountPalindromicSubsequence cps = new CountPalindromicSubsequence();
    System.out.println(cps.countPalindromicSubsequence("aabca"));
  }
}
